//
//  IconPickerViewController.swift
//  Checklists
//
//  Created by cygarm on 15/12/2.
//  Copyright © 2015年 Razeware. All rights reserved.
//

import UIKit

protocol IconPickerViewControllerDelegete: class {
	func iconPicker(picker: IconPickerViewController, didPickIcon iconName: String)
}

class IconPickerViewController: UITableViewController {
	weak var delegate: IconPickerViewControllerDelegete?
	
	let icons = [
		"No Icon",
		"Appointments",
		"Birthdays",
		"Chores",
		"Drinks",
		"Folder",
		"Groceries",
		"Inbox",
		"Photos",
		"Trips"]
	
	//MARK: UITableViewController Data Source
	override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
		return icons.count
	}
	
	override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
		let cell = tableView.dequeueReusableCellWithIdentifier("IconCell")! as UITableViewCell
		
		let iconName = icons[indexPath.row]
		cell.textLabel!.text = iconName
		cell.imageView!.image = UIImage(named: iconName)
		
		return cell
	}
	
	override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
		if let delegate = delegate {
			let iconName = icons[indexPath.row]
			delegate.iconPicker(self, didPickIcon: iconName)
		}
	}
}
